package com.yimi.yinhepda.db.dao;

import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;
import com.yimi.yinhepda.base.BaseApplication;
import com.yimi.yinhepda.db.helper.DbHelper;
import com.yimi.yinhepda.db.table.LoadUnloadTimeTable;

import java.sql.SQLException;

/**
 * 装卸车时间提醒表.
 *
 * @author 000432
 * @date 2018/8/10 0010
 */

public class LoadUnloadTimeTableDao extends BaseDao<LoadUnloadTimeTable, Long> {

    public LoadUnloadTimeTableDao() {
        super(DbHelper.getInstance(BaseApplication.getContext()), LoadUnloadTimeTable.class);
    }

    public LoadUnloadTimeTable getData(String userCode, String companyCode, String unloadTaskNo) {
        try {
            if (getDbHelper() != null && getDbHelper().isOpen()) {
                QueryBuilder<LoadUnloadTimeTable, Long> queryBuilder = dao.queryBuilder();
                Where where = queryBuilder.where();
                where.eq("userCode", userCode)
                        .and().eq("compCode", companyCode)
                        .and().eq("unloadTaskNo", unloadTaskNo);
                LoadUnloadTimeTable entity = queryBuilder.queryForFirst();
                return entity;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
